package com.openmind.pichostring.vo;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * ${name}
 *
 * @author zhoujunwen
 * @date 2019-09-11
 * @time 10:51
 * @desc
 */
@Getter
@Setter
public class RespVo<T> implements Serializable {
    private static final long serialVersionUID = 914966603775234693L;
    private int code  = 0;
    private String message = "成功";
    private T data;

    private RespVo() {
    }

    private RespVo(T data) {
        this.data = data;
    }

    public static <T> RespVo<T> ok() {
        return new RespVo<>();
    }

    public static <T> RespVo<T> ok(T data) {
        return new RespVo<>(data);
    }

    public static <T> RespVo<T> ok(String message) {
        RespVo<T> respVo = new RespVo<>();
        respVo.setMessage(message);
        return respVo;
    }

    public static <T> RespVo<T> error(int code, String message, T data) {
        RespVo<T> respVo = new RespVo<>();
        respVo.setCode(code);
        respVo.setMessage(message);
        respVo.setData(data);
        return respVo;
    }

    public static <T> RespVo<T> error(ErrorCode errorCode, T data) {
        return error(errorCode.getCode(),errorCode.getMessage(), data);
    }
}
